package com.senlingspace.framework.support;

import com.senlingspace.framework.security.context.SecurityContextHolderExt;

/**
 * 小程序分页工具类，只处理 pageNum 和 pageSize
 *
 * @author lebronjames
 * @date 2024/09/30
 */
public class WeChatMiniAppPageSupport {

    /**
     * 获取当前页码
     */
    public static Integer getPageNum() {
        return getParameter("page_num", 1);
    }

    /**
     * 获取每页条数
     */
    public static Integer getPageSize() {
        return getParameter("page_size", 10);
    }

    /**
     * 从 SecurityContextHolderExt 获取参数值
     */
    private static Integer getParameter(String key, Integer defaultValue) {
        return SecurityContextHolderExt.get(key, Integer.class) != null ?
                SecurityContextHolderExt.get(key, Integer.class) : defaultValue;
    }

}
